﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FluentNHibernate.Mapping;
using YasharEl.Infrastructure.Core.Personification;
using YasharEl.Infrastructure.Core.PersistenceModel.NHibernate.Personification.UserTypes;
using YasharEl.Infrastructure.Core.EntityModel.Users;

namespace YasharEl.Infrastructure.Core.PersistenceModel.NHibernate.Users.Mappings
{
    public class UserEntityMap : ClassMap<UserEntity>
    {
        public UserEntityMap()
        {
            ReadOnly();
            Table("PE_USERS");
            Id(e => e.UserId)
                .Column("USER_ID")
                .GeneratedBy
                    .Identity();

            Map(e => e.UserIdentityId)
                .Column("USER_IDENTITY_NUMBER")
                .Not.Nullable()
                .CustomType<IsraelIdentityNumberUserType>();
            Component<Name>(e => e.UserName,
                nameEntity =>
                {
                    nameEntity.Access.Property();
                    nameEntity.Map(n => n.Firstname)
                        .Column("FIRSTNAME")
                        .Not.Nullable()
                        .Length(50);
                    nameEntity.Map(n => n.Lastname)
                        .Column("LASTNAME")
                        .Not.Nullable()
                        .Length(50);
                }
            );
        }
    }
}
